package com.leetcode.no167;

public class Solution {
    public int[] twoSum(int[] numbers, int target) {
        int len = numbers.length;
//        int[] result = new int[2];
        int left = 0, right = len - 1;

        while (left < right) {
            while (right > left) {
                if (numbers[left] + numbers[right] == target)
                    return new int[]{left + 1, right + 1};
                right--;
            }
            right = len - 1;
            left++;
        }

        return new int[]{-1, -1};
    }


    public int[] twoSum02(int[] numbers, int target) {
        int len = numbers.length;

        int left = 0, right = len - 1;

        while (left != right) {
            int sum = numbers[left] + numbers[right];
            if (sum == target) {
                return new int[]{left + 1, right + 1};
            } else if (sum > target) {
                right--;
            } else if (sum < target) {
                left++;
            }
        }

        return new int[]{-1, -1};
    }
}
